home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-18 | 42.6 KB | 1,304 lines | [TEXT/MPS ] |
- C.S.M.P. Digest Thu, 26 Mar 92 Volume 1 : Issue 31
-
- Today's Topics:
-
- Pointer arithmatic in Pascal question
- Code modules in a program - how to implement?
- How do you write an MDEF that handles scrolling?
- Select Directory dialog
- Where's that code frag that finds the app file ?
-
-
- The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
-
- These digests are available (by using FTP, account anonymous, your email
- address as password) in the pub/mac/csmp-digest directory on ftp.cs.uoregon.
- edu. This is also the home of the comp.sys.mac.programmer Frequently Asked
- Questions list.
-
- These digests are also available via email. Just send a note saying that you
- want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
- automatically receive each new digest as it is created.
-
- The articles in these digests are taken directly from comp.sys.mac.programmer.
- They are not edited; all articles included in this digest are in their original
- posted form. The only articles that are -not- included in these digests are
- those which didn't receive any replies (except those that give information
- rather than ask a question). All replies to each article are concatenated
- onto the original article in the order in which they were received. Article
- threads are not added to the digests until the last article added to the
- thread is at least one month old (this is to ensure that the thread is dead
- before adding it to the digests).
-
- Send administrative mail to mkelly@cs.uoregon.edu.
-
- -------------------------------------------------------
-
- From: vivanco@ciit85.ciit.nrc.ca
- Subject: Pointer arithmatic in Pascal question
- Date: 27 Jan 92 11:17:14 GMT
- Organization: National Research Council
-
- Hi, I usually program in C where pointer arithmatic is widely used. Now, I
- need a variable 2D array of integers. In C, I would allocate a 1D array and
- use pointer arithmatic to acces the array as a 2D array. Can you do a similar
- thing in Pascal?
-
- Thanks in advance,
-
- Rodrigo
-
-
-
- - -------------------------
-
- From: jmatthews@desire.wright.edu
- Subject: Pointer arithmatic in Pascal question
- Date: 29 Jan 92 04:42:20 GMT
- Organization: Wright State University
-
- In article <1992Jan27.171715.1088@ciit85.ciit.nrc.ca>, vivanco@ciit85.ciit.nrc.ca writes:
- > Hi, I usually program in C where pointer arithmatic is widely used. Now, I
- > need a variable 2D array of integers. In C, I would allocate a 1D array and
- > use pointer arithmatic to acces the array as a 2D array. Can you do a similar
- > thing in Pascal?
-
- Depending on the nature of your data, Pascal may provide more elegant
- solutions, but pointer arithmetic works fine in Pascal. To avaiod heap
- fragmentation, allocate space with Newhandle, call MoveHHi and HLock it.
- Call StripAddress on the handle's master pointer and use that as the base of
- the array. Calling ord() on a pointer renders a LongInt, and calling pointer()
- on a LongInt is assignment compatible with any pointer type.
-
- type IntPtr = ^Integer;
- const xDim = columns-1; yDim = rows-1;
- var h: Handle; p: IntPtr;
- ...
- h:= NewHandle(xDim*yDim*2);
- if h <> nil then
- begin
- MoveHHi(h);
- HLock(h);
- p:= IntPtr(StripAddress(h^))
- end
- else p:= nil;
- ...
- procedure SetArray(p:IntPtr; x,y,i:Integer; {p^[x,y]:=i}
- begin
- p:= IntPtr(ord(p) + y*xDim*2 + x*2); {or however you want to base the array}
- p^:= i
- end;
- ...
- function GetArray(p:IntPtr; x,y:Integer):Integer;
- begin
- p:= IntPtr(ord(p) + y*xDim*2 + x*2); {or however you want to base the array}
- GetArray:= p^
- end;
-
- Range checking is left as an exercise. Hope this helps.
-
- o----------------------------------------------------------------------------o
- | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- | "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
- o----------------------------------------------------------------------------o
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Pointer arithmatic in Pascal question
- Date: 30 Jan 92 22:52:28 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <1992Jan28.234220.1589@desire.wright.edu> jmatthews@desire.wright.edu writes:
- >In article <1992Jan27.171715.1088@ciit85.ciit.nrc.ca>, vivanco@ciit85.ciit.nrc.ca writes:
- >> Hi, I usually program in C where pointer arithmatic is widely used. Now, I
- >> need a variable 2D array of integers. In C, I would allocate a 1D array and
- >> use pointer arithmatic to acces the array as a 2D array. Can you do a similar
- >> thing in Pascal?
- >
- >Depending on the nature of your data, Pascal may provide more elegant
- >solutions, but pointer arithmetic works fine in Pascal. To avaiod heap
- >fragmentation, allocate space with Newhandle, call MoveHHi and HLock it.
- >Call StripAddress on the handle's master pointer and use that as the base of
- >the array. Calling ord() on a pointer renders a LongInt, and calling pointer()
- >on a LongInt is assignment compatible with any pointer type.
-
- I'd suggest taking a little different approach the one described above.
- Given the original poster's needs, there should be no need to move the
- handle high in the heap, lock it, or call StripAddress on the master
- pointer. On the other hand, there are several reason why you shouldn't
- call those routines. Instead, assuming an array of integers, use
- something like the following:
-
- TYPE
- IntArray = ARRAY [0..0] OF INTEGER; { actually variable sized }
- IntArrayPtr = ^IntArray;
- IntArrayHdl = ^IntArrayPtr;
-
- VAR
- myArray: IntArrayHdl;
-
- BEGIN
- myArray = IntArrayHdl(NewHandle(someSize));
- { now initialize all elements to one. }
- for i := 0 to width do begin
- for j := 0 to height do begin
- {$PUSH} {$R-} {turn off range checking}
- myArray^^[j*width+i] := 1;
- {$POP} {restore previsous settings}
- end;
- end;
- END.
-
- This is just off the top of my head, so I hope I'm not too far off.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: vivanco@ciit85.ciit.nrc.ca
- Subject: Pointer arithmatic in P (Thanks)
- Date: 4 Feb 92 04:40:21 GMT
- Organization: National Research Council
-
- In article <1992Jan28.234220.1589@desire.wright.edu>, jmatthews@desire.wright.edu writes:
- > In article <1992Jan27.171715.1088@ciit85.ciit.nrc.ca>, vivanco@ciit85.ciit.nrc.ca writes:
- >> Hi, I usually program in C where pointer arithmatic is widely used. Now, I
- >> need a variable 2D array of integers. In C, I would allocate a 1D array and
- >> use pointer arithmatic to acces the array as a 2D array. Can you do a similar
- >> thing in Pascal?
- >
- > Depending on the nature of your data, Pascal may provide more elegant
- > solutions, but pointer arithmetic works fine in Pascal. To avaiod heap
- > fragmentation, allocate space with Newhandle, call MoveHHi and HLock it.
- > Call StripAddress on the handle's master pointer and use that as the base of
- > the array. Calling ord() on a pointer renders a LongInt, and calling pointer()
- > on a LongInt is assignment compatible with any pointer type.
- >
- > type IntPtr = ^Integer;
- > const xDim = columns-1; yDim = rows-1;
- > var h: Handle; p: IntPtr;
- > ...
- > h:= NewHandle(xDim*yDim*2);
- > if h <> nil then
- > begin
- > MoveHHi(h);
- > HLock(h);
- > p:= IntPtr(StripAddress(h^))
- > end
- > else p:= nil;
- > ...
- > procedure SetArray(p:IntPtr; x,y,i:Integer; {p^[x,y]:=i}
- > begin
- > p:= IntPtr(ord(p) + y*xDim*2 + x*2); {or however you want to base the array}
- > p^:= i
- > end;
- > ...
- > function GetArray(p:IntPtr; x,y:Integer):Integer;
- > begin
- > p:= IntPtr(ord(p) + y*xDim*2 + x*2); {or however you want to base the array}
- > GetArray:= p^
- > end;
- >
- > Range checking is left as an exercise. Hope this helps.
- >
- > o----------------------------------------------------------------------------o
- > | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- > | "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
- > o----------------------------------------------------------------------------o
-
- Thanks, that's the way I did it. Except I typed cast the pointer into a Longint
- and then back. The reason I asked was that in C you can declare a pointer and
- use it like an array, syntax wise. The compiler takes care of addressing
- depending on the size of an element. Thanks toIngemar Ragnemalm for a similar
- suggestion.
-
- Rodrigo.
-
-
-
- - -------------------------
-
- From: dent@DIALix.oz.au (Andrew Dent)
- Subject: Pointer arithmatic in P (Thanks)
- Date: 7 Feb 92 13:50:06 GMT
- Organization: DIALix Services, Perth, Western Australia
-
- To save type-casting for pointer increments, I wrote the following
- library. Note that it costs a LITTLE in performance, pushing the arguments
- on the stack, compared to straight addition code, but may be worth it for
- readability:
-
- Andy - share and enjoy!
-
- unit ptrTools;
- { functions for incrementing and decrementing various 2 and 4 byte values }
- { EG: incP(aPtr) nextPtr:=plus1P(aPtr) less4I(integerToDecrease) }
-
- { copyright 1990 A.D. Software, free for all use provided this }
- { copyright notice retained }
-
- { "Ad ware" - other products that may interest you: }
- { Shareware: Fast File Compare }
- { Freeware: various Hypercard & FoxBASE+/Mac XCMDS, including }
- {setting SF open/save path, get monitor bit depth etc. }
- { and Think Pascal Code & Resource for an Open dialog with prompt string }
-
- { Retail: Fortran->Pascal translator and Fortran formatted}
- {I/O runtime libraries. }
- { COMING SOON - classified magazine entry/management/printing system }
-
- {Andy Dent A.D. Software phone/fax 61-9-249-2719 }
- { Mac & VAX programmer 94 Bermuda Dve , Ballajura}
- { Internet: dent@dialix.oz.au Western Australia 6066}
- { Compuserve: 100033,3241 }
-
- { NOTE: if you want to increase the constants (up to 8) then change }
- { the second digit of the SUBQ or ADDQ line }
- { ADD is even, 0=8 2=1 4=2 6=3 8=4 A=5 C=6 E=7 }
- { SUB is odd, 1=8 3=1 5=2 7=3 9=4 B=5 D=6 F=7 }
-
-
- interface
-
-
- {************************************************************}
- { L O N G I N T }
- {************************************************************}
-
- { F U N C T I O N S }
-
- function Plus1L (l: longint): longint;
- inline
- $5297, {ADDQ.L #$1, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Plus2L (l: longint): longint;
- inline
- $5497, {ADDQ.L #$2, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Plus3L (l: longint): longint;
- inline
- $5697, {ADDQ.L #$3, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Plus4L (l: longint): longint;
- inline
- $5897, {ADDQ.L #$4, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
-
- function Less1L (l: longint): longint;
- inline
- $5397, {SUBQ.L #$1, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Less2L (l: longint): longint;
- inline
- $5597, {SUBQ.L #$2, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Less3L (l: longint): longint;
- inline
- $5797, {SUBQ.L #$3, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
- function Less4L (l: longint): longint;
- inline
- $5997, {SUBQ.L #$4, (A7) }
- $2E9F; {MOVE.L (A7)+, (A7) }
-
-
-
-
- { P R O C E D U R E S }
- procedure incL (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5290; {ADDQ.L #$1, (A0) }
-
- procedure inc2L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5490; {ADDQ.L #$2, (A0) }
-
- procedure inc3L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5690; {ADDQ.L #$3, (A0) }
-
- procedure inc4L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5890; {ADDQ.L #$4, (A0) }
-
-
- procedure decL (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5390; {SUBQ.L #$1, (A0) }
-
- procedure dec2L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5590; {SUBQ.L #$2, (A0) }
-
- procedure dec3L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5790; {SUBQ.L #$3, (A0) }
-
- procedure dec4L (var l: longint);
- inline
- $205f, {MOVEA.L (A7)+, A0 }
- $5990; {SUBQ.L #$4, (A0) }
-
-
-
- {***********************************************}
- { P T R }
- {***********************************************}
-
- { F U N C T I O N S }
- function Plus1P (p: univ ptr): ptr;
- inline
- $5297, {ADDQ.L #$1, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Plus2P (p: univ ptr): ptr;
- inline
- $5497, {ADDQ.L #$2, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Plus3P (p: univ ptr): ptr;
- inline
- $5697, {ADDQ.L #$3, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Plus4P (p: univ ptr): ptr;
- inline
- $5897, {ADDQ.L #$4, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
-
- function Less1P (p: univ ptr): ptr;
- inline
- $5397, {SUBQ.L #$1, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Less2P (p: univ ptr): ptr;
- inline
- $5597, {SUBQ.L #$2, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Less3P (p: univ ptr): ptr;
- inline
- $5797, {SUBQ.L #$3, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
- function Less4P (p: univ ptr): ptr;
- inline
- $5997, {SUBQ.L #$4, (A7) }
- $2E9F; {MOVE.P (A7)+, (A7) }
-
-
-
-
- { P R O C E D U R E S }
- procedure incP (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5290; {ADDQ.L #$1, (A0) }
-
- procedure inc2P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5490; {ADDQ.L #$2, (A0) }
-
- procedure inc3P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5690; {ADDQ.L #$3, (A0) }
-
- procedure inc4P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5890; {ADDQ.L #$4, (A0) }
-
-
- procedure decP (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5390; {SUBQ.L #$1, (A0) }
-
- procedure dec2P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5590; {SUBQ.L #$2, (A0) }
-
- procedure dec3P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5790; {SUBQ.L #$3, (A0) }
-
- procedure dec4P (var p: ptr);
- inline
- $205f, {MOVEA.P (A7)+, A0 }
- $5990; {SUBQ.L #$4, (A0) }
-
-
-
-
- {**************************************************}
- { I N T E G E R }
- {**************************************************}
-
- { F U N C T I O N S }
- function Plus1I (i: integer): integer;
- inline
- $5257, {ADDQ.W #$1, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Plus2I (i: integer): integer;
- inline
- $5457, {ADDQ.W #$2, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Plus3I (i: integer): integer;
- inline
- $5657, {ADDQ.W #$3, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Plus4I (i: integer): integer;
- inline
- $5857, {ADDQ.W #$4, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
-
- function Less1I (i: integer): integer;
- inline
- $5357, {SUBQ.W #$1, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Less2I (i: integer): integer;
- inline
- $5557, {SUBQ.W #$2, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Less3I (i: integer): integer;
- inline
- $5757, {SUBQ.W #$3, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
- function Less4I (i: integer): integer;
- inline
- $5957, {SUBQ.W #$4, (A7) }
- $3E9F; {MOVE.W (A7)+, (A7) }
-
-
-
-
- { P R O C E D U R E S }
- procedure incI (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5250; {ADDQ.W #$1, (A0) }
-
- procedure inc2I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5450; {ADDQ.W #$2, (A0) }
-
- procedure inc3I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5650; {ADDQ.W #$3, (A0) }
-
- procedure inc4I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5850; {ADDQ.W #$4, (A0) }
-
-
- procedure decI (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5350; {SUBQ.W #$1, (A0) }
-
- procedure dec2I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5550; {SUBQ.W #$2, (A0) }
-
- procedure dec3I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5750; {SUBQ.W #$3, (A0) }
-
- procedure dec4I (var i: integer);
- inline
- $205f, {MOVEA.W (A7)+, A0 }
- $5950; {SUBQ.W #$4, (A0) }
-
- implementation
- end.
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Pointer arithmatic in Pascal question
- Date: 30 Jan 92 22:52:28 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <1992Jan28.234220.1589@desire.wright.edu> jmatthews@desire.wright.edu writes:
- >In article <1992Jan27.171715.1088@ciit85.ciit.nrc.ca>, vivanco@ciit85.ciit.nrc.ca writes:
- >> Hi, I usually program in C where pointer arithmatic is widely used. Now, I
- >> need a variable 2D array of integers. In C, I would allocate a 1D array and
- >> use pointer arithmatic to acces the array as a 2D array. Can you do a similar
- >> thing in Pascal?
- >
- >Depending on the nature of your data, Pascal may provide more elegant
- >solutions, but pointer arithmetic works fine in Pascal. To avaiod heap
- >fragmentation, allocate space with Newhandle, call MoveHHi and HLock it.
- >Call StripAddress on the handle's master pointer and use that as the base of
- >the array. Calling ord() on a pointer renders a LongInt, and calling pointer()
- >on a LongInt is assignment compatible with any pointer type.
-
- I'd suggest taking a little different approach the one described above.
- Given the original poster's needs, there should be no need to move the
- handle high in the heap, lock it, or call StripAddress on the master
- pointer. On the other hand, there are several reason why you shouldn't
- call those routines. Instead, assuming an array of integers, use
- something like the following:
-
- TYPE
- IntArray = ARRAY [0..0] OF INTEGER; { actually variable sized }
- IntArrayPtr = ^IntArray;
- IntArrayHdl = ^IntArrayPtr;
-
- VAR
- myArray: IntArrayHdl;
-
- BEGIN
- myArray = IntArrayHdl(NewHandle(someSize));
- { now initialize all elements to one. }
- for i := 0 to width do begin
- for j := 0 to height do begin
- {$PUSH} {$R-} {turn off range checking}
- myArray^^[j*width+i] := 1;
- {$POP} {restore previsous settings}
- end;
- end;
- END.
-
- This is just off the top of my head, so I hope I'm not too far off.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- ---------------------------
-
- From: mhall@occs.cs.oberlin.edu (Matthew Hall)
- Subject: Code modules in a program - how to implement?
- Date: 28 Jan 92 21:05:43 GMT
- Organization: Oberlin College Computer Science
-
- Hello -
- My question is this - How can I write a program that will, at
- run time, load a code resource, and pass information to it, and then
- have the code resource return to the original program, passing more
- information. I am thinking along the lines of Mandelzot, where
- the program acts as a shell almost and programmers can create their
- own modules to do what they want.
- I assume I will have to use assembly - which is not too good
- for me, but if I don't need to do too much I can use Think Pascal's
- inline assembler. Also, it seems, I can not use global variables or
- call new() or dispose() frome the code - but I can probably deal with
- that. Would it be a question of loading the code resoursce, locking
- it, pushing the variables onto the stack, and then jumping to the code
- resources handle? (The code resource would be structured like a DA or
- CDEV - one procedure at the start of the code that takes messages and
- information and passes them on) Am I being way too naive? Can you
- help me? Please respond.
-
- Matt Hall
- mhall@occs.edu
- --
-
- <<mhall@occs.edu OR
- <<SMH9666@OBERLIN.BITNET
-
- This is just a beta version signature
-
-
-
- - -------------------------
-
- From: mhall@occs.cs.oberlin.edu (Matthew Hall)
- Subject: Code Modules - how to use.
- Date: 29 Jan 92 21:43:57 GMT
- Organization: Oberlin College Computer Science
-
-
- I have had several inquiries for a followup since I asked my
- question of how to call, at runtime, other code resources that were
- not linked to the main program at compile time. These can be written
- by other programmers to add different functions or effects to a main
- program - MandelZot and IFS (I think) use this so that programmers can
- add new fractal algorithms.
- The only response that I have had so far is to look in Tech
- Note #256. It's availible in the Tech Note Stack from ftp.apple.com
- or individually at archive.umich.edu
- (/mac/development/apple/tech.notes/tn.251.300)
- I haven't had a chance to download it yet. (I tried downloading the
- TNStack a few weeks ago, but it got corrupted in the process, and
- destroyed my system 7 folder when I tried to unstuff it. That's okay,
- I was getting sick of Sys 7 anyways. And the neat thing is, alaises I
- made under Sys 7 work under sys 6.0.7. But I digress)
- Anyway, if anyone else has more information, please reply and
- I will summarize.
-
- Thank you-
- Matt Hall
-
- --
-
- <<mhall@occs.edu OR
- <<SMH9666@OBERLIN.BITNET
-
- This is just a beta version signature
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Code modules in a program - how to implement?
- Date: 30 Jan 92 22:21:01 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <MHALL.92Jan28160543@occs.cs.oberlin.edu> mhall@occs.cs.oberlin.edu (Matthew Hall) writes:
- >Hello -
- > My question is this - How can I write a program that will, at
- >run time, load a code resource, and pass information to it, and then
- >have the code resource return to the original program, passing more
- >information. I am thinking along the lines of Mandelzot, where
- >the program acts as a shell almost and programmers can create their
- >own modules to do what they want.
- > I assume I will have to use assembly - which is not too good
- >for me, but if I don't need to do too much I can use Think Pascal's
- >inline assembler. Also, it seems, I can not use global variables or
- >call new() or dispose() frome the code - but I can probably deal with
- >that. Would it be a question of loading the code resoursce, locking
- >it, pushing the variables onto the stack, and then jumping to the code
- >resources handle? (The code resource would be structured like a DA or
- >CDEV - one procedure at the start of the code that takes messages and
- >information and passes them on) Am I being way too naive? Can you
- >help me? Please respond.
-
- I guess you're using Pascal, but this is easier in C, so I'll show
- it first.
-
- Assume you want to call a function with the following declaration:
-
- long myFunc(short, long);
-
- Further assume that this function is in the external resource PROC(1),
- with the entry point at the first byte of the resource. You would then
- use the following code to call it:
-
- typedef long (*MyFuncPtr)(short, long);
-
- Handle myCode;
-
- myCode = GetResource('PROC', 1);
- myLongResult = ((MyFuncPtr) *myCode)(myShort, myLong);
-
- In Pascal, it is more difficult to deal with function pointers. I
- believe that you would have to use something like the following:
-
- FUNCTION CallExternal(someInteger: INTEGER; someLong: LONGINT;
- someProc: Ptr): LONGINT;
- INLINE $205F, { MOVE.L (A7)+,A0 }
- $4E90; { JSR (A0) }
-
- myCode: Handle;
-
- myCode := GetResource('PROC', 1);
- myLongResult := CallExternal(myInteger, myLong, myCode^);
-
- My Pascal is a little rusty, so I hope I'm not too far off.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: CXT105@psuvm.psu.edu (Christopher Tate)
- Subject: Code modules in a program - how to implement?
- Date: 31 Jan 92 02:46:26 GMT
- Organization: Penn State University
-
- In article <62297@apple.Apple.COM>, keith@Apple.COM (Keith Rollin) says:
- >
- >Assume you want to call a function with the following declaration:
- >
- >long myFunc(short, long);
- >
- >Further assume that this function is in the external resource PROC(1),
- >with the entry point at the first byte of the resource. You would then
- >use the following code to call it:
- >
- >typedef long (*MyFuncPtr)(short, long);
- >
- >Handle myCode;
- >
- >myCode = GetResource('PROC', 1);
- >myLongResult = ((MyFuncPtr) *myCode)(myShort, myLong);
-
- Shouldn't you flush the caches between the GetResource() and the function
- call so as not to terminally confuse a Quadra?
-
- Or am I completely off base on just when you should and shouldn't flush
- the caches? The subject has come up recently, but I haven't seen any
- explanation of *when* this sort of thing is necessary. Maybe it's time
- for something like the "When to call StripAddress()" tech note....
-
- - -----
- Christopher Tate | Cryptogram #16:
- cxt105@psuvm.psu.edu |
- CXT105@PSUVM.BITNET | JUI EKO AJ BKSI OJPF JZM NKF FPU YIAAIF
- - -------------------| XV AJ ZJJS PQ ALI QFXNI JC K UIE JUI.
- Send me the answer! |
-
-
-
- - -------------------------
-
- From: thomp@netcom.COM (Thom Phillabaum)
- Subject: Code modules in a program - how to implement?
- Date: 31 Jan 92 21:08:15 GMT
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
-
- One small, somewhat subtle detail is that you should also lock the handle to
- the CODE resource. Otherwise, if the CODE resource makes any toolbox call
- the Memory Manager is likely to scoot things around (including the code it's
- executing) when compacting the heap. Needless to say, this would be a
- sub-optimal situation. Anyway, that's my two bits...
-
- thomp@netcom.com
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Code modules in a program - how to implement?
- Date: 3 Feb 92 03:09:52 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <92030.214626CXT105@psuvm.psu.edu> CXT105@psuvm.psu.edu (Christopher Tate) writes:
- >In article <62297@apple.Apple.COM>, keith@Apple.COM (Keith Rollin) says:
- >>
- >>Assume you want to call a function with the following declaration:
- >>
- >>long myFunc(short, long);
- >>
- >>Further assume that this function is in the external resource PROC(1),
- >>with the entry point at the first byte of the resource. You would then
- >>use the following code to call it:
- >>
- >>typedef long (*MyFuncPtr)(short, long);
- >>
- >>Handle myCode;
- >>
- >>myCode = GetResource('PROC', 1);
- >>myLongResult = ((MyFuncPtr) *myCode)(myShort, myLong);
- >
- >Shouldn't you flush the caches between the GetResource() and the function
- >call so as not to terminally confuse a Quadra?
- >
- >Or am I completely off base on just when you should and shouldn't flush
- >the caches? The subject has come up recently, but I haven't seen any
- >explanation of *when* this sort of thing is necessary. Maybe it's time
- >for something like the "When to call StripAddress()" tech note....
-
- You're completely correct in that the instruction cache should be
- cleared when loading in a resource with executable code in it.
- Fortunately, GetResource and LoadResource do this for you.
-
- Flushing the instruction cache is necessary if you whip up instructions
- on the fly. For instance, a common method for implementing things like
- custom control and menus includes utilizing a 6 byte resource. The
- first word of the resource contains a JMP instruction, and the
- following long word gets filled in by the application with the address
- of the application function that implements the 'real' defProc code.
- After this address is written, the instruction cache should be
- flushed. On the other hand, if the JMP $xxxxxxxx instruction in the
- resource were replaced with something like the following, you wouldn't
- need to worry about flushing the cache:
-
- MyMDEF PROC
-
- LEA Address,A0
- MOVE.L (A0),A0
- JMP (A0)
- Address DC.L 0 ; Get's filled in by application
- ; after resource is loaded.
- ENDP
-
- (I can't remember if the first two instructions can be shortened to
- a mere MOVE.L Address,A0 so please excuse any verbosity.)
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Code modules in a program - how to implement?
- Date: 30 Jan 92 22:21:01 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <MHALL.92Jan28160543@occs.cs.oberlin.edu> mhall@occs.cs.oberlin.edu (Matthew Hall) writes:
- >Hello -
- > My question is this - How can I write a program that will, at
- >run time, load a code resource, and pass information to it, and then
- >have the code resource return to the original program, passing more
- >information. I am thinking along the lines of Mandelzot, where
- >the program acts as a shell almost and programmers can create their
- >own modules to do what they want.
- > I assume I will have to use assembly - which is not too good
- >for me, but if I don't need to do too much I can use Think Pascal's
- >inline assembler. Also, it seems, I can not use global variables or
- >call new() or dispose() frome the code - but I can probably deal with
- >that. Would it be a question of loading the code resoursce, locking
- >it, pushing the variables onto the stack, and then jumping to the code
- >resources handle? (The code resource would be structured like a DA or
- >CDEV - one procedure at the start of the code that takes messages and
- >information and passes them on) Am I being way too naive? Can you
- >help me? Please respond.
-
- I guess you're using Pascal, but this is easier in C, so I'll show
- it first.
-
- Assume you want to call a function with the following declaration:
-
- long myFunc(short, long);
-
- Further assume that this function is in the external resource PROC(1),
- with the entry point at the first byte of the resource. You would then
- use the following code to call it:
-
- typedef long (*MyFuncPtr)(short, long);
-
- Handle myCode;
-
- myCode = GetResource('PROC', 1);
- myLongResult = ((MyFuncPtr) *myCode)(myShort, myLong);
-
- In Pascal, it is more difficult to deal with function pointers. I
- believe that you would have to use something like the following:
-
- FUNCTION CallExternal(someInteger: INTEGER; someLong: LONGINT;
- someProc: Ptr): LONGINT;
- INLINE $205F, { MOVE.L (A7)+,A0 }
- $4E90; { JSR (A0) }
-
- myCode: Handle;
-
- myCode := GetResource('PROC', 1);
- myLongResult := CallExternal(myInteger, myLong, myCode^);
-
- My Pascal is a little rusty, so I hope I'm not too far off.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- ---------------------------
-
- From: jwwalker@opusc.csd.scarolina.edu (Jim Walker)
- Subject: How do you write an MDEF that handles scrolling?
- Organization: Univ. of S. Carolina, Department of Mathematics
- Date: Wed, 29 Jan 1992 13:31:53 GMT
-
-
- Does anyone know where I can get sample code for an MDEF that handles
- pop-ups and scrolling? Inside Mac is pretty sketchy on scrolling.
- Specifically, what are the low-memory globals AtMenuBottom and MBSaveLoc
- used for? (I think I understand about TopMenuItem.)
-
- The Pascal MDEF in the May '91 Snippets does not handle scrolling. The
- skeleton MDEF in THINK Reference does not handle scrolling. The UMPG does
- not discuss the subject.
- --
- -- Jim Walker 76367.2271@compuserve.com walkerj@math.scarolina.edu
-
-
-
- - -------------------------
-
- From: haynes@mace.cc.purdue.edu (Carl W. Haynes III)
- Subject: How do you write an MDEF that handles scrolling?
- Date: 29 Jan 92 21:20:12 GMT
- Organization: Purdue University Computing Center
-
- In article <1992Jan29.133153.16679@opusc.csd.scarolina.edu> walkerj@math.scarolina.edu writes:
- >
- >Does anyone know where I can get sample code for an MDEF that handles
- >pop-ups and scrolling? Inside Mac is pretty sketchy on scrolling.
- >Specifically, what are the low-memory globals AtMenuBottom and MBSaveLoc
- >used for? (I think I understand about TopMenuItem.)
-
- The example MDEF in Dave Mark's "Macintosh C programming Promer Vol II"
- handles both scrolling and pop-ups. The example
- in the text of the book doesn't handle these, but if you look at the
- code in Appendix B, this code has been added.
-
- carl
- haynes@mace.cc.purdue.edu
-
-
-
- - -------------------------
-
- From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
- Subject: How do you write an MDEF that handles scrolling?
- Date: 29 Jan 92 22:53:56 GMT
- Organization: Symantec Corp.
-
- >>>>> On Wed, 29 Jan 1992 13:31:53 GMT, jwwalker@opusc.csd.scarolina.edu (Jim Walker) said:
-
- > Does anyone know where I can get sample code for an MDEF that
- > handles pop-ups and scrolling? Inside Mac is pretty sketchy on
- > scrolling. Specifically, what are the low-memory globals
- > AtMenuBottom and MBSaveLoc used for? (I think I understand about
- > TopMenuItem.)
-
- > The Pascal MDEF in the May '91 Snippets does not handle scrolling.
- > The skeleton MDEF in THINK Reference does not handle scrolling.
- > The UMPG does not discuss the subject.
-
- Hi Jim,
-
- How about the MDEF that Apple has released? It doesn't do pop-ups (I
- think), but it does hierarchical menus and scrolling. It's on the
- developer CDs, and you can ftp it from ftp.apple.com (in
- dts/mac/defprocs.6.0.x). The readme there claims that it's from System
- 6.0.4.
-
- -phil
- - --
- Phil Shapiro Technical Support Analyst
- Language Products Group Symantec Corporation
- Internet: phils@chaos.cs.brandeis.edu
- --
- Phil Shapiro Technical Support Analyst
- Language Products Group Symantec Corporation
- Internet: phils@chaos.cs.brandeis.edu
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: How do you write an MDEF that handles scrolling?
- Date: 30 Jan 92 23:29:08 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <PHILS.92Jan29175356@chaos.cs.brandeis.edu> phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
- >>>>>> On Wed, 29 Jan 1992 13:31:53 GMT, jwwalker@opusc.csd.scarolina.edu (Jim Walker) said:
- >
- > > Does anyone know where I can get sample code for an MDEF that
- > > handles pop-ups and scrolling? Inside Mac is pretty sketchy on
- > > scrolling. Specifically, what are the low-memory globals
- > > AtMenuBottom and MBSaveLoc used for? (I think I understand about
- > > TopMenuItem.)
- >
- > > The Pascal MDEF in the May '91 Snippets does not handle scrolling.
- > > The skeleton MDEF in THINK Reference does not handle scrolling.
- > > The UMPG does not discuss the subject.
- >
- >How about the MDEF that Apple has released? It doesn't do pop-ups (I
- >think), but it does hierarchical menus and scrolling. It's on the
- >developer CDs, and you can ftp it from ftp.apple.com (in
- >dts/mac/defprocs.6.0.x). The readme there claims that it's from System
- >6.0.4.
-
- I'm pretty sure the Apple provided MDEF source handles popups, since
- it's straight out of the source code used to build the System. However,
- since it's from 6.0.4, it doesn't handle the new 7.0 things, like true
- gray for disabled items and help balloons.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: How do you write an MDEF that handles scrolling?
- Date: 30 Jan 92 23:29:08 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <PHILS.92Jan29175356@chaos.cs.brandeis.edu> phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
- >>>>>> On Wed, 29 Jan 1992 13:31:53 GMT, jwwalker@opusc.csd.scarolina.edu (Jim Walker) said:
- >
- > > Does anyone know where I can get sample code for an MDEF that
- > > handles pop-ups and scrolling? Inside Mac is pretty sketchy on
- > > scrolling. Specifically, what are the low-memory globals
- > > AtMenuBottom and MBSaveLoc used for? (I think I understand about
- > > TopMenuItem.)
- >
- > > The Pascal MDEF in the May '91 Snippets does not handle scrolling.
- > > The skeleton MDEF in THINK Reference does not handle scrolling.
- > > The UMPG does not discuss the subject.
- >
- >How about the MDEF that Apple has released? It doesn't do pop-ups (I
- >think), but it does hierarchical menus and scrolling. It's on the
- >developer CDs, and you can ftp it from ftp.apple.com (in
- >dts/mac/defprocs.6.0.x). The readme there claims that it's from System
- >6.0.4.
-
- I'm pretty sure the Apple provided MDEF source handles popups, since
- it's straight out of the source code used to build the System. However,
- since it's from 6.0.4, it doesn't handle the new 7.0 things, like true
- gray for disabled items and help balloons.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- ---------------------------
-
- From: S_HAERDLE@iravcl.ira.uka.de (|S| Tilman Haerdle)
- Subject: Select Directory dialog
- Date: 29 Jan 1992 13:13:54 GMT
- Organization: University of Karlsruhe, FRG (Informatik Rechnerabteilung)
-
- Hi,
-
- i would like to implement a dialog box to allow the user choosing a directory
- similar to the standard "open file"-dialog. mpw poses such a dialog, when i have
- installed MacApp (dialog : "Where is your MacApp folder
-
- anyone out there who has customized sfpgetfile or has done it using
- MacApp 2.0 ???????
-
- thanks,
-
- tilman
-
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Select Directory dialog
- Date: 30 Jan 92 22:40:06 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <koda4iINNhe9@iraul1.ira.uka.de> S_HAERDLE@iravcl.ira.uka.de (|S| Tilman Haerdle) writes:
- >Hi,
- >
- >i would like to implement a dialog box to allow the user choosing a directory
- >similar to the standard "open file"-dialog. mpw poses such a dialog, when i have
- >installed MacApp (dialog : "Where is your MacApp folder
- >
- >anyone out there who has customized sfpgetfile or has done it using
- >MacApp 2.0 ???????
-
- Mac DTS Sample Code #18: Stdfile addresses this issue. You can get this
- sample code from Apple's ftp site (ftp.apple.com), from APDA, or from
- many other ftp sites and BBS's.
-
- The sample code sited customizes SFPGetFile. While it was not written
- with MacApp in mind, there is no reason why you cannot incorporate into
- your MacApp program.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Select Directory dialog
- Date: 30 Jan 92 22:40:06 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <koda4iINNhe9@iraul1.ira.uka.de> S_HAERDLE@iravcl.ira.uka.de (|S| Tilman Haerdle) writes:
- >Hi,
- >
- >i would like to implement a dialog box to allow the user choosing a directory
- >similar to the standard "open file"-dialog. mpw poses such a dialog, when i have
- >installed MacApp (dialog : "Where is your MacApp folder
- >
- >anyone out there who has customized sfpgetfile or has done it using
- >MacApp 2.0 ???????
-
- Mac DTS Sample Code #18: Stdfile addresses this issue. You can get this
- sample code from Apple's ftp site (ftp.apple.com), from APDA, or from
- many other ftp sites and BBS's.
-
- The sample code sited customizes SFPGetFile. While it was not written
- with MacApp in mind, there is no reason why you cannot incorporate into
- your MacApp program.
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- ---------------------------
-
- From: e-sink@uiuc.edu (Eric W. Sink)
- Subject: Where's that code frag that finds the app file ?
- Date: 29 Jan 92 16:45:16 GMT
- Organization: University of Illinois at Urbana-Champaign
-
- People have asked this before, but I need that piece of code which
- finds the location of its own application file. I want to locate
- the app and search in that directory for some files.
-
- Wasn't it something like CurResFile() and then some PBstuffCalls ?
-
- Is in the UMPG ? (I know I've seen it somewhere... :-)
-
- adThanksvance.
-
- --
- Eric W. Sink, Spatial Analysis and Systems Team
- USACERL, P.O. Box 9005, Champaign, IL 61826-9005
- 1-800-USA-CERL x449, e-sink@uiuc.edu
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Where's that code frag that finds the app file ?
- Date: 30 Jan 92 22:55:09 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <1992Jan29.164516.6306@sunb10.cs.uiuc.edu> e-sink@uiuc.edu writes:
- >People have asked this before, but I need that piece of code which
- >finds the location of its own application file. I want to locate
- >the app and search in that directory for some files.
- >
- >Wasn't it something like CurResFile() and then some PBstuffCalls ?
- >
- >Is in the UMPG ? (I know I've seen it somewhere... :-)
-
- Probably Inside Mac. The call you want is HGetVol. Call it when
- your application starts up, and before you change the default
- directory (if you do that at all).
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- - -------------------------
-
- From: jmatthews@desire.wright.edu
- Subject: Where's that code frag that finds the app file ?
- Date: 1 Feb 92 04:09:22 GMT
- Organization: Wright State University
-
- In article <62301@apple.Apple.COM>, keith@Apple.COM (Keith Rollin) writes:
- > In article <1992Jan29.164516.6306@sunb10.cs.uiuc.edu> e-sink@uiuc.edu writes:
- >>People have asked this before, but I need that piece of code which
- >>finds the location of its own application file. I want to locate
- >>the app and search in that directory for some files.
- >>
- >>Wasn't it something like CurResFile() and then some PBstuffCalls ?
- >>
- >>Is in the UMPG ? (I know I've seen it somewhere... :-)
- >
- > Probably Inside Mac. The call you want is HGetVol. Call it when
- > your application starts up, and before you change the default
- > directory (if you do that at all).
-
- Also call the Segment Loader's GetAppParms to find out what the user has
- (re)named your application.
-
- o----------------------------------------------------------------------------o
- | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- | "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
- o----------------------------------------------------------------------------o
-
-
-
- - -------------------------
-
- From: keith@Apple.COM (Keith Rollin)
- Subject: Where's that code frag that finds the app file ?
- Date: 30 Jan 92 22:55:09 GMT
- Organization: Apple Computer Inc., Cupertino, CA
-
- In article <1992Jan29.164516.6306@sunb10.cs.uiuc.edu> e-sink@uiuc.edu writes:
- >People have asked this before, but I need that piece of code which
- >finds the location of its own application file. I want to locate
- >the app and search in that directory for some files.
- >
- >Wasn't it something like CurResFile() and then some PBstuffCalls ?
- >
- >Is in the UMPG ? (I know I've seen it somewhere... :-)
-
- Probably Inside Mac. The call you want is HGetVol. Call it when
- your application starts up, and before you change the default
- directory (if you do that at all).
-
- --
- - ----------------------------------------------------------------------------
- Keith Rollin --- <Taligent .signature under construction>
- Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
-
-
-
- ---------------------------
-
- End of C.S.M.P. Digest
- **********************
-